package com.sx.art2.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.sx.art2.beans.Auction;
import com.sx.art2.beans.User;
import com.sx.art2.service.AuctionService;
import com.sx.art2.tools.Page;

@Controller
@RequestMapping("/Auction")
public class AuctionController {


	@Autowired
	AuctionService auctionService;
	@RequestMapping("/addAuction")
	public ModelAndView addAuction(Auction auction,HttpSession session) {
		
		ModelAndView mv= new ModelAndView();
		User user=(User)session.getAttribute("User");
		auction.setUserId(user.getUserId());
		SimpleDateFormat dateFormat =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		auction.setAuctionTime(dateFormat.format(new Date()));
		auctionService.addAuction(auction);
		mv.setViewName("redirect:/AuctionInfo/lookArt?sign=0&auctionInfoId="+auction.getAuctionInfoId());
		return mv;
	}
	
	@RequestMapping("/selectByArtId")
	public ModelAndView selectByArtId(int artId) {
		
		Page page=new Page();
		System.out.println(page.getPageSize());
		page.setPageSize(5);
		page.setPageNow(1);
		List<Auction> list=auctionService.selectByArtId(artId, page);
		System.out.println(list);
		return null;
	}
	@RequestMapping("/selectByUserId")
	public ModelAndView selectByUserId(HttpSession session) {
		ModelAndView mv=new ModelAndView();
		User user=(User)session.getAttribute("User");
		Page page=new Page();
		page.setPageSize(5);
		page.setPageNow(1);
		List<Auction> list=auctionService.selectByUserId(user.getUserId(), page);		        
		mv.addObject("list", list);
		mv.setViewName("wdjp");
		return mv;
	}
	@RequestMapping("/selectByauctionInfoId")
	public ModelAndView selectByauctionInfoId(int auctionInfoId) {
		ModelAndView mv=new ModelAndView();
		List<Auction> list=auctionService.selectByauctionInfoId(auctionInfoId);
		mv.addObject("list", list);
		mv.setViewName("admin/auction-show");
		return mv;
	}
	
}
